package com.gzh.animatortext.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.gzh.animatortext.util.PublicUtil

/**
 * @创建者 顾朝辉
 * @创建时间 2021/5/28 10:23
 * @描述
 */
class CircleView : View {
    var paintBig: Paint = Paint()
    var paintLittle: Paint = Paint()
    var mViewCenterX: Int = 0
    var mViewCenterY: Int = 0

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context, attrs, defStyleAttr
    )

    init {
        paintBig.color = Color.parseColor("#49555555") //颜色
        paintBig.style = Paint.Style.STROKE //描边
        paintBig.flags = Paint.ANTI_ALIAS_FLAG //抗锯齿
        paintBig.strokeWidth = 7f
        paintLittle.color = Color.parseColor("#49000000") //颜色
        paintLittle.style = Paint.Style.FILL //实心
        paintLittle.flags = Paint.ANTI_ALIAS_FLAG //抗锯齿
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        mViewCenterX = measuredWidth / 2
        mViewCenterY = measuredHeight / 2
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        canvas?.let {
            it.drawCircle(
                mViewCenterX.toFloat(),
                mViewCenterY.toFloat(),
                mViewCenterX.toFloat() - 14f,
                paintBig
            )
            it.drawCircle(mViewCenterX.toFloat(), 14f, 10f, paintLittle)
        }
    }
}